<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/11 0011
 * Time: 15:41
 */

namespace app\home\controller;


use app\model\model\Ad;
use app\model\model\Sample_type;
use app\model\model\Seo;
use app\model\model\Visiting;
use think\Request;

class Sample extends Base
{
    //实例化
    protected $_Seo;
    protected $_Ad;
    protected $_Sample;
    protected $_Sample_type;
    protected $_v;
    protected $_Page;
    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->_Sample_type = new Sample_type();
        $this->_Ad = new Ad();
        $this->_v = new Visiting();
        $this->_Sample = new \app\model\model\Sample();
        $this->_Seo = new Seo();
        $this->_Page = new \app\model\model\Page();
    }
    public function index(){
        $u = $_SERVER['REQUEST_URI'];
        if(strpos($u,'home')!==false){
            $this->redirect('/sample.html',301);
        }
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>8,'flag'=>1]);
        $this->assign('banner',$banner);
        //分类

            $type = $this->_Sample_type->getListSelect(true);
        $index = $this->_Sample_type->getOne(43);
        $this->assign('index',$index);

        $this->assign('type',$type);
        $this->assign('type1',input('type'));
        //列表
        if(input('type')){
            $list = $this->_Sample->getListSelect(['type_id'=>input('type'),'flag'=>1],true);
        }else{
            $list = $this->_Sample->getListSelect(['flag'=>1],true);
        }
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function getListBytype(){
        if(input('type')){
            $list = $this->_Sample->getListSelect(['type_id'=>input('type'),'flag'=>1],true);
        }else{
            $list = $this->_Sample->getListSelect(['flag'=>1],true);
        }

        return json_echo_msg(200,'chenggong',$list);
    }
    //客户来访
    public function index1(){
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>9,'flag'=>1]);
        $this->assign('banner',$banner);
        //列表
        $list = $this->_v->getListHome(['flag'=>1]);
        $this->assign('list',$list);
        $page = $this->_Page->getOne(18);
        $this->assign('index',$page);
        return $this->fetch();
    }
}